package com.huangkailong.designpattern.composite.lucence;

import java.util.ArrayList;
import java.util.List;

/**
 * @author huangkl
 * @since 1.0.0
 */
public class CoursePackage implements Course {
    private final String name;
    private final Double price;
    private final List<Course> courses;

    /**
     * 构造函数.
     *
     * @param name  名称
     * @param price 价格
     */
    public CoursePackage(String name, Double price) {
        this.name = name;
        this.price = price;
        this.courses = new ArrayList<>();
    }

    @Override
    public void showInfo(int level) {
        for (int i = 0; i < level; i++) {
            System.out.print("\t");
        }
        System.out.printf("+-%s\n", name);
        for (Course course : courses) {
            course.showInfo(level + 1);
        }
    }

    @Override
    public boolean addCourse(Course course) {
        return courses.add(course);
    }

    @Override
    public boolean removeCourse(Course course) {
        return courses.remove(course);
    }

    @Override
    public String getCourseName() {
        return name;
    }

    @Override
    public Double getPrice() {
        return price;
    }
}
